﻿using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Xna.Framework.Input;


namespace WorldOnFire
{
    class CMenuMain : ABCMenu
    {
        public enum eOptions
        {
            PLAY_,
            OPTIONS_,
            CREDITS,
            CHEATS,
            EXIT,
            COUNT
        };

        public enum eExpandableOptions
        {
            PLAY,
            OPTIONS,
            COUNT
        };

        public enum ePlayOptions
        {
            CAMPAIGN,
            SKIRMISH,
            COUNT
        };

        public enum eOptionsOptions
        {
            CONTROLS,
            VIDEO,
            AUDIO,
            COUNT
        };

        public override void Initialize()
        {
            // Initialize the options
            m_nOptionCount = (int)eOptions.COUNT;
            m_strOptionTitles = new string[(int)eOptions.COUNT] 
            {
                "Play",
                "Options",
                "Credits",
                "Cheats",
                "Exit"
            };

            // Initialize the expandable options
            m_nExpandableOptionCount = (int)eExpandableOptions.COUNT;
            m_ExpandableOptions = new tExpandableOption[(int)eExpandableOptions.COUNT];
            m_nExpandableOptionIndices = new int[(int)eExpandableOptions.COUNT]
            {
                (int)eOptions.PLAY_,
                (int)eOptions.OPTIONS_
            };

            // Set the data for each expandable option
            m_ExpandableOptions[(int)eExpandableOptions.PLAY].nOptionCount = (int)ePlayOptions.COUNT;
            m_ExpandableOptions[(int)eExpandableOptions.PLAY].strOptionTitles = new string[(int)ePlayOptions.COUNT]
            {
                "Campaign",
                "Skirmish"
            };

            m_ExpandableOptions[(int)eExpandableOptions.OPTIONS].nOptionCount = (int)eOptionsOptions.COUNT;
            m_ExpandableOptions[(int)eExpandableOptions.OPTIONS].strOptionTitles = new string[(int)eOptionsOptions.COUNT]
            {
                "Controls",
                "Video",
                "Audio"
            };

            base.Initialize();
        }

        public override void Input(float _fDeltaTime)
        {
            // TODO: FUCKING INPUT. JESUS CHRIST.

            if (SInputManager.IsKeyPressed(Keys.Enter) == true)
            {
                switch( m_nSelectedIndex )
                {
                    case (int)eOptions.PLAY_:
                        {
                            // If the selection is expanded,
                            if( m_bSelectionExpanded == true )
                            {
                                // The expanded option handles input
                                switch( m_ExpandableOptions[(int)eExpandableOptions.PLAY].nSelectedIndex )
                                {
                                    case (int)ePlayOptions.CAMPAIGN:
                                        {
                                            s_StateManager.Switch(new CMenuPauseCampaign());
                                        }
                                        break;
                                    case (int)ePlayOptions.SKIRMISH:
                                        {
                                            s_StateManager.Switch(new CLobbySkirmish());
                                        }
                                        break;
                                }
                            }
                            // If the selection is not expanded
                            else
                            {
                                // Expand it
                                m_bSelectionExpanded = true;
                            }
                        }
                        break;
                    case (int)eOptions.OPTIONS_:
                        {
                            // If the selection is expanded,
                            if( m_bSelectionExpanded == true )
                            {
                                // The expanded option handles input
                                switch (m_ExpandableOptions[(int)eExpandableOptions.OPTIONS].nSelectedIndex)
                                {
                                    case (int)eOptionsOptions.CONTROLS:
                                        {

                                        }
                                        break;
                                    case (int)eOptionsOptions.VIDEO:
                                        {
                                            s_StateManager.Push(new CMenuOptionsVideo());
                                        }
                                        return;
                                    case (int)eOptionsOptions.AUDIO:
                                        {
                                            s_StateManager.Push(new CMenuOptionsAudio());
                                        }
                                        return;
                                }
                            }
                            // If the selection is not expanded
                            else
                            {
                                // Expand it
                                m_bSelectionExpanded = true;
                            }
                        }
                        break;
                    case (int)eOptions.CREDITS:
                        {
                        }
                        break;
                    case (int)eOptions.CHEATS:
                        {

                        }
                        break;
                    case (int)eOptions.EXIT:
                        {
                            s_Game.Exit();
                        }
                        break;
                }
            }

            base.Input(_fDeltaTime);
        }
    }
}
